package wyklad;

import java.io.*;
import javax.servlet.*;
import javax.servlet.http.*;

class ByteArrayServletOutputStream extends ServletOutputStream {
	ByteArrayOutputStream baos;
	
	ByteArrayServletOutputStream() {
		this.baos = new ByteArrayOutputStream();
	}
	
	@Override
	public void write(int b) throws IOException {
		baos.write(b);		
	}
	
	ByteArrayOutputStream toByteArrayOutputStream() {
		return baos;
	}
	
	byte[] toByteArray() {
		return baos.toByteArray();
	}
}

public class ZamienNaHtmlWrapper extends HttpServletResponseWrapper {
	public ZamienNaHtmlWrapper(HttpServletResponse response) {
		super(response);
	}
	
	private ByteArrayServletOutputStream basos = new ByteArrayServletOutputStream();
	private PrintWriter pw = new PrintWriter(basos.toByteArrayOutputStream());
	
	public PrintWriter getWriter() {
		return pw;
	}
	
	public ServletOutputStream getOutputStream() {
		return basos;
	}
	
	byte[] toByteArray() {
		return basos.toByteArray();
	}
}
